import { defineStore } from "pinia";
import {useStaffInfoApi} from '../utils/api/StaffInfoApi'

interface StaffFace{
    staff_name:string,
    staff_department:string,
    staff_position:string,
    staff_phone:string,
    staff_address:string,
    staff_time:string
}
export const useStaffsStore = defineStore('staffs',{
    state:()=>({
        staffsInfo:[{}] as Array<StaffFace>
}),

    getters:{
        stateStaffs:(state:any)=>{
            return state.staffsInfo
        }
    },

    actions:{
        //添加员工
        addStaff(Staff:any){
            const newStaff = {
                staff_name:   Staff.name,
                staff_department: Staff.department,
                staff_position:   Staff.position,
                staff_phone:  Staff.phone,
                staff_address:    Staff.address,
                staff_time:    Staff.jobTime
            }
            this.staffsInfo.push(newStaff)
        },
        async getAllStaff(){
            //调用api方法，获取请求的方法
            const {response,error,fatchData} = useStaffInfoApi('/staff','get')
            //调用请求方法请求数据
            await fatchData()
            if(response.value){
                this.staffsInfo = response.value
            }
        }
    }
})